import Compressor from 'compressorjs'
export default {
  data () {
    return {
    }
  },
  methods: {
    // 图片压缩上传公共方法
    imageCompressUpload (obj, url, params) {
      console.log('压缩前图片', obj.file)
      const _this = this
      /* eslint-disable no-new */
      new Compressor(obj.file, {
        quality: 0.2,
        success (result) {
          const file = new window.File([result], result.name, { type: result.type })
          console.log('压缩后图片', file)
          _this.$axios.upload(url, file, params).then(res => {
            console.log('上传成功')
          })
        }
      })
    }
  }
}
